package com.alpha.eceasy.mall.config;

import com.alpha.eceasy.mall.client.HWAdminApiClient;
import com.alpha.eceasy.mall.client.UserRequestClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.support.WebClientAdapter;
import org.springframework.web.service.invoker.HttpServiceProxyFactory;

@Configuration
public class RestClientConfig {
    @Bean
    public UserRequestClient userRequestClient(@Value("${subServer.hw-boos}") String baseUrl) {
        WebClient client = WebClient.builder()
                .baseUrl(baseUrl)
                .build();
        HttpServiceProxyFactory factory = HttpServiceProxyFactory.builder(WebClientAdapter.forClient(client))
                .build();
        return factory.createClient(UserRequestClient.class);
    }
    @Bean
    public HWAdminApiClient hwAdminApiClient(@Value("${subServer.hw-api}") String baseUrl) {
        WebClient client = WebClient.builder()
                .baseUrl(baseUrl)
                .build();
        HttpServiceProxyFactory factory = HttpServiceProxyFactory.builder(WebClientAdapter.forClient(client))
                .build();
        return factory.createClient(HWAdminApiClient.class);
    }

}